package com.ask.dto;

import com.sun.net.httpserver.Authenticator;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Result implements Serializable {
    private static final long serialVersionUID = 1l;

    private static final String MESSAGE_SUCCESS = "success";
    private static final Integer CODE_SUCCESS = 100;
    private static final String MESSAGE_FAIL = "fail";
    private static final Integer CODE_FAIL = 200;

    private Integer code;
    private String message;
    private Object data;
    private Boolean success;


    public static Result success(Object data) {
        return Result.builder()
                .message(MESSAGE_SUCCESS)
                .data(data)
                .code(null)
                .success(true)
                .build();
    }

    public static Result success(Object data, String msg) {
        return Result.builder()
                .message(msg)
                .data(data)
                .code(null)
                .success(true)
                .build();
    }

    public static Result fail(String message) {
        return Result.builder()
                .message(message)
                .data(null)
                .code(CODE_FAIL)
                .success(false)
                .build();
    }

    public static Result success() {
        return Result.builder()
                .message(MESSAGE_SUCCESS)
                .data(null)
                .code(CODE_SUCCESS)
                .success(true)
                .build();
    }

}
